#ifndef __DC_SERIAL_SCREEN_H__
#define __DC_SERIAL_SCREEN_H__

#include "common.h"

/* 大彩屏通信参数 */
#define DC_SCREEN_UART_DEVICE    "uart3"
#define DC_SCREEN_BAUD_RATE      115200
#define DC_SCREEN_BUFFER_SIZE    256

/* 大彩屏指令集 */
#define DC_CMD_READ_REG          0x01    /* 读寄存器 */
#define DC_CMD_WRITE_REG         0x02    /* 写寄存器 */
#define DC_CMD_READ_VP           0x03    /* 读变量 */
#define DC_CMD_WRITE_VP          0x04    /* 写变量 */
#define DC_CMD_READ_STR          0x05    /* 读字符串 */
#define DC_CMD_WRITE_STR         0x06    /* 写字符串 */
#define DC_CMD_READ_BIT          0x07    /* 读位变量 */
#define DC_CMD_WRITE_BIT         0x08    /* 写位变量 */
#define DC_CMD_RUN_SCRIPT        0x09    /* 运行脚本 */
#define DC_CMD_STOP_SCRIPT       0x0A    /* 停止脚本 */
#define DC_CMD_UPDATE_SCREEN     0x0B    /* 更新屏幕 */

/* 屏幕页面定义 */
typedef enum {
    SCREEN_MAIN = 0,        /* 主页面 */
    SCREEN_MONITOR,         /* 监控页面 */
    SCREEN_SETTINGS,        /* 设置页面 */
    SCREEN_ALARMS,          /* 报警页面 */
    SCREEN_TRENDS,          /* 趋势页面 */
    SCREEN_DIAGNOSTICS      /* 诊断页面 */
} screen_page_t;

/* 控件地址定义 */
typedef enum {
    /* 主页面控件 */
    MAIN_TEMP1_VALUE = 0x1000,
    MAIN_TEMP2_VALUE = 0x1001,
    MAIN_FLOW1_VALUE = 0x1002,
    MAIN_FLOW2_VALUE = 0x1003,
    MAIN_PRESSURE_VALUE = 0x1004,
    MAIN_WATER_QUALITY = 0x1005,
    MAIN_VALVE_POSITION = 0x1006,
    MAIN_PID_OUTPUT = 0x1007,
    MAIN_SYSTEM_STATUS = 0x1008,
    
    /* 设置页面控件 */
    SET_TEMP_SETPOINT = 0x2000,
    SET_PID_KP = 0x2001,
    SET_PID_KI = 0x2002,
    SET_PID_KD = 0x2003,
    SET_ALARM_LIMITS = 0x2004,
    SET_SYSTEM_MODE = 0x2005,
    
    /* 报警页面控件 */
    ALARM_LIST_START = 0x3000,
    ALARM_COUNT = 0x3100,
    
    /* 趋势页面控件 */
    TREND_DATA_START = 0x4000,
    TREND_INTERVAL = 0x4100
} screen_control_t;

/* 屏幕消息类型 */
typedef enum {
    SCREEN_MSG_PAGE_CHANGE = 1,
    SCREEN_MSG_BUTTON_PRESS,
    SCREEN_MSG_DATA_UPDATE,
    SCREEN_MSG_ALARM_NOTIFY
} screen_msg_type_t;

/* 函数声明 */
rt_err_t dc_screen_init(void);
rt_err_t dc_screen_write_register(uint16_t addr, uint16_t value);
rt_err_t dc_screen_write_variable(uint16_t addr, float value);
rt_err_t dc_screen_write_string(uint16_t addr, const char *str);
rt_err_t dc_screen_change_page(screen_page_t page);
rt_err_t dc_screen_update_data(void);
rt_err_t dc_screen_send_alarm(uint8_t alarm_id, const char *alarm_msg);

#endif /* __DC_SERIAL_SCREEN_H__ */